package com.laboratory.servicecustomer.controller;

import com.laboratory.servicecustomer.constant.constantArgs;
import com.laboratory.servicecustomer.utilPojo.comm;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author acok
 * @description: shiro异常处理类
 * @Date 2022/12/5 10:12
 * @Version 1.0
 */

@ControllerAdvice
public class permissionException {
    @ResponseBody
    @ExceptionHandler(UnauthenticatedException.class)
    public Object unauthenticatedException(Exception e){
        comm comm=new comm();
        comm.setCode(constantArgs.COMMUNITY_FAIL_CODE);
        comm.setMessage(constantArgs.COMMUNITY_AUTHENTICATED_EXCEPTION);
        return comm;
    }
    @ResponseBody
    @ExceptionHandler(AuthorizationException.class)
    public Object authorizationException(Exception e){
        comm comm=new comm();
        comm.setCode(constantArgs.COMMUNITY_FAIL_CODE);
        comm.setMessage(constantArgs.COMMUNITY_AUTHORIZATION_EXCEPTION);
        return comm;
    }
}
